import java.util.HashSet;
import java.util.Iterator;


public class State
{
	protected int					stateId;
	protected String				stateName;
	protected boolean				isInitial;
	protected boolean				isFinal;
	protected HashSet<Transition>	transitions;
	
	public State()
	{
		transitions = new HashSet<Transition>();
	}
	
	public State(State s)
	{
		stateId = s.stateId;
		stateName = s.stateName;
		isInitial = s.isInitial;
		isFinal = s.isFinal;
		transitions = s.transitions; 
	}
	
	public State(int id, String name)
	{
		stateId = id;
		stateName = name;
		transitions = new HashSet<Transition>();
		isInitial = false;
		isFinal = false;
	}
	
	public State(int id, String name, boolean isInitial, boolean isFinal)
	{
		stateId = id;
		stateName = name;
		this.isInitial = isInitial;
		this.isFinal = isFinal;
		transitions = new HashSet<Transition>();
	}
	
	/**
	 * @return the transitions
	 */
	public HashSet<Transition> getTransitions()
	{
		return transitions;
	}
	
	/**
	 * @param transitions
	 *            the transitions to set
	 */
	public void setTransitions(HashSet<Transition> transitions)
	{
		this.transitions = transitions;
	}
	
	/**
	 * @return the stateId
	 */
	public int getStateId()
	{
		return stateId;
	}
	
	/**
	 * @param stateId
	 *            the stateId to set
	 */
	public void setStateId(int stateId)
	{
		this.stateId = stateId;
	}
	
	/**
	 * @return the stateName
	 */
	public String getStateName()
	{
		return stateName;
	}
	
	/**
	 * @param stateName
	 *            the stateName to set
	 */
	public void setStateName(String stateName)
	{
		this.stateName = stateName;
	}
	
	/**
	 * @return the isInitial
	 */
	public boolean isInitial()
	{
		return isInitial;
	}
	
	/**
	 * @param isInitial
	 *            the isInitial to set
	 */
	public void setInitial(boolean isInitial)
	{
		this.isInitial = isInitial;
	}
	
	/**
	 * @return the isFinal
	 */
	public boolean isFinal()
	{
		return isFinal;
	}
	
	/**
	 * @param isFinal
	 *            the isFinal to set
	 */
	public void setFinal(boolean isFinal)
	{
		this.isFinal = isFinal;
	}
	
	public String toString()
	{
		return "\nEtat : " + stateName + (isInitial ? "(I)" : "") + (isFinal ? "(F)" : "") + "\t transitions vers : " + transitions + "";
	}
	
	public boolean equals(State s)
	{
		return (s.stateId == this.stateId);
	}
	
	protected Object clone()
	{
		State res = new State();
		Iterator<Transition> it = this.transitions.iterator();
		Transition t;
		
		res.isFinal = this.isFinal;
		res.isInitial = this.isInitial;
		res.stateId = this.stateId;
		res.stateName = this.stateName;
		
		while(it.hasNext())
		{
			t = it.next();			
			res.transitions.add(t);
		}
		
		return res;
	}
	
	public State copy()
	{
		return (State) this.clone();
	}
	
}
